$(function() {
	optFormater();
	ajaxTable();
	
});
function ajaxTable() {
	$('#invmbTable').datagrid({
		toolbar : [ 
		],
		frozenColumns:[[
			{field:"ck", checkbox:true}
		]],
		pageNumber : 1,
		loadMsg : '数据加载中,请稍后...',
		pageList : [ 10, 30, 50, 100 ],
		onLoadError : function() {
			alert('数据加载失败!');
		},
		queryParams : {
		},
		onClickRow : function(rowIndex, rowData) {
			$('#invmbTable').datagrid('unselectRow', rowIndex);
		},
		onDblClickRow : function(rowIndex, rowData) {
			
	    }
	}).datagrid('acceptChanges');
}
function reloadTable() {
	$('#invmbTable').datagrid('reload');
	$('#invmbTable').datagrid('clearSelections');
}
function optFormater() {
	var update = '';
	if(globalMaps.get('4') != undefined && maac == 'N') {
		update += "<a href='#' onclick='deleteSalmamb(\""+maaa+"\",\""+maab+"\")' class='easyui-linkbutton' plain='true' iconCls='icon-cancel'>删除</a>";
	}
	if(globalMaps.get('5') != undefined && maac == 'N') {
		update += "<a href='#' onclick='auditSalmamb(\""+maaa+"\",\""+maab+"\",\"Y\")' class='easyui-linkbutton' plain='true' iconCls='icon-tip'>审核</a>";
	}
	if(globalMaps.get('6') != undefined && maac == 'Y') {
		update += "<a href='#' onclick='auditSalmamb(\""+maaa+"\",\""+maab+"\",\"C\")' class='easyui-linkbutton' plain='true' iconCls='icon-tip'>指定结束</a>";
		update += "<a href='#' onclick='auditSalmamb(\""+maaa+"\",\""+maab+"\",\"N\")' class='easyui-linkbutton' plain='true' iconCls='icon-tip'>撤销审核</a>";
	}
	if(globalMaps.get('6') != undefined && maac == 'C') {
		update += "<a href='#' onclick='auditSalmamb(\""+maaa+"\",\""+maab+"\",\"Y\")' class='easyui-linkbutton' plain='true' iconCls='icon-tip'>撤销结束</a>";
	}
	if(globalMaps.get('7') != undefined && maac == 'Y') {
		update += "<a href='#' onclick='auditSalmamb(\""+maaa+"\",\""+maab+"\",\"V\")' class='easyui-linkbutton' plain='true' iconCls='icon-tip'>作废</a>";
	}
	$("#menuDiv").html(update);
	$.parser.parse($("#menuDiv"));
}

//-------------SHENHE---
function auditSalmamb(maaa,maab,flag) {
	changeStatus('/wms/invmb/auditInvmb.xhtml?maaa=' + maaa + '&maab=' + maab+ '&flag=' + flag);
	window.parent.returnValue=1;
	window.close();

}
function deleteSalmamb(maaa,maab) {
	$.messager.confirm('删除提示', '你确定删除该采购单吗?', function(r) {
		if(r) {
			changeStatus('/wms/invmb/delSalmamb.xhtml?maaa=' + maaa + '&maab=' + maab);
			window.parent.returnValue=1;
			window.close();
		}
	});
}
function saveSalmamb(){
	var validateResult = $("#headForm").form('validate');
	if(validateResult == false) {
		return false;
	}
	$('#headForm').submit();
}
function changeStatus(url){
	$.ajax({
		async : false,
		cache : false,
		type : 'POST',
		dataType : "text",
		url : url,
		error : function () {
			alert('请求失败');
		},
		success : function(result){
			if(result=="success") {
//				alert("操作成功!");
			} else {
				alert(result);
			}
			reloadTable();
		}
	});
}
window.onbeforeunload = function(){  
	var n = window.event.screenX - window.screenLeft;   
    var b = n > document.documentElement.scrollWidth-20;   //		
      if(b&&window.event.clientY<0||window.event.altKey){   
//    	  delSalmbAll();
//          alert("是关闭而非刷新");   
//          window.event.returnValue   =   "是否关闭？";
      }else{
//             alert("是刷新而非关闭");   
     }  
 } ;

